package com.wxh.bomb.netty.design.masterwoker;

import com.wxh.bomb.netty.design.masterwoker.core.Master;
import com.wxh.bomb.netty.design.masterwoker.core.Task;
import com.wxh.bomb.netty.design.masterwoker.service.MyWorker;

import java.util.Random;

/**
 * @author wxh
 * @date：2017.10.10
 */
public class Main {

    public static void main(String[] args) {
        System.out.println("我的机器可用Processor数量:" + Runtime.getRuntime().availableProcessors());
        Master master = new Master(new MyWorker(), Runtime.getRuntime().availableProcessors());
        Random r = new Random();
        for (int i = 1; i <= 100; i++) {
            Task t = new Task();
            t.setId(i);
            t.setName("任务" + i);
            t.setPrice(r.nextInt(1000));
            master.submit(t);
        }
        master.execute();
        long start = System.currentTimeMillis();
        int ret = master.getResult();
        long end = System.currentTimeMillis() - start;
        System.out.println("最终结果：" + ret + "， 执行耗时：" + end);

    }

}
